<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/includes.jsp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>生产返工编辑</title>
	<!-- import css and js --> 
	<%@ include file="/common/metaInput.jsp" %>  
	<script src="${ctx}/js/jsp/comm.js" type="text/javascript"></script>
	<script type="text/javascript" src="${ctx}/js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
var basic_Url="${ctx}/logic/prorework";
var grid;
$(function(){
$("#inputForm").validate({			   
	onsubmit: true,
	 /*执行ajaxsubmit  */ 
    submitHandler: function(editform) {
            
        //alert(jsonInfo); 
        try{			    		
            url =  basic_Url+"/save.do";
            var api = frameElement.api;
        	var W = api.opener;
        
            getReturnMessage(url,"inputForm",W.searchAP);
        }catch(e){alert(e);}
    }
 }
);
$("#save").hide();
$("#tijiao").hide();
if('${rework.zd008Billstatus}'=="PROREWORK_SAVE"||'${rework.zd008Billstatus}'==""||'${rework.zd008Billstatus}'==null){
	$("#save").show();
	$("#tijiao").show();
}
grid = $("#dataGrid").ligerGrid({
    columns: [{ display: 'ID', name: 'id', width: 1 , hide:true},
              { display: '产品id', name: 'zd006MaterialsId', width: 1 , hide:true},
              { display: '<font color="gray">产品编码</font>', name: 'zd006MaterialsCode',  width: 100},
			  { display: '<font color="gray">产品名称</font>', name: 'zd006MaterialsName', width: 100 },
			  { display: '<font color="gray">产品型号</font>', name: 'zd010MaterialsModel', width: 100},
			  { display: '<font color="gray">产品尺寸</font>', name: 'zd023MaterialsSize', width: 160},
			  { display: '<font color="gray">计量单位</font>', name: 'zd012MaterialsUnit', width: 60},
			  { display: '<font color="gray">工序名称</font>', name: 'zd029ProcessName', width: 80,render: function (item){
        		  if(item.basicProcessDO==null){
        			  return item.zd029Process;
        		  }else{
        			  return item.basicProcessDO.zd002Name;
        		  }
        	  }},
			  { display: '<font color="gray">生产车间</font>', name: 'zd028WorkShopName', width: 80,render: function (item){
        		  if(item.basicWorkshopDO==null){
        			  return item.zd028WorkShop;
        		  }else{
        			  return item.basicWorkshopDO.zd002Name;
        		  }
        	  }},
			  { display: '<font color="gray">订单数量</font>', name: 'zd030PlanQuantity', width: 80},
			  { display: '<font color="gray">已返工数量</font>', name: 'zd016ProductionQuantity', width: 80},
			  { display: '返工数量<font color="red">*</font>', name: 'zd013Quantity', width: 80,editor : {type :'float'}},
			  { display: '单价<font color="red">*</font>', name: 'zd014Price', width: 80},
			  { display: '', name: 'zd007UseCode', width: 80,hide:true},
			  { display: '工作人员<font color="red">*</font>', name: 'zd008UseName', width: 80},
              { display: '<font color="gray">产品描述</font>', name: 'zd021MaterialsDescription', width: 150}
              ],
              enabledEdit: true,
              usePager: true,pageSize:1000,pageSizeOptions:[1000],
              parms:[{ name : 'id' , value : '${rework.id}'}],
              url : basic_Url+"/griditems.do",
              width: "100%", height:'90%', checkbox: true,
              toolbar: { items: [
                                 { text: '选择人员', click: PersonWindow, icon: 'add' },
                                 { line: true },
                                 { text: '删除', click: deleteRow, img: '${ctx}/js/ligerUI/skins/icons/delete.gif' }
                                 ]
                       }
 });
}); 
//生产调度单列表
function PlanWindow(){
		getDG().dialog(
				{
					title : '选择生产派工单',
					width : 650,
					height : 350,
					content : 'url:' + sys_context
							+ '/public/windowalert/dispatching.do?type=1',    
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var rows = this.content.getSelected();
						if (rows != null) {
							$(rows).each(function() {
								$("#zd004CustomerId").val(this.zd004CustomerId);
								$("#zd004CustomerCode").val(this.zd004CustomerCode);
								$("#zd004CustomerName").val(this.zd004CustomerName);
								$("#zd002OriCode").val(this.zd001FormCode);
								$("#zd003PiCode").val(this.zd003PiCode);
								var url=basic_Url+"/gridBomitems.do?id="+this.id;
								multipleSearch("#dataGrid",true,"",url);
							});
						}
						this.content.Close();
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
}

//人员列表
function PersonWindow(){
	var mrows = grid.getCheckedRows();
	if (mrows.length == 0) {
		$.dialog.alert("请选择要返工的工序！");
		return false;
	}
		getDG().dialog(
				{
					title : '选择生产工人',
					width : 650,
					height : 350,
					content : 'url:' + sys_context
							+ '/public/windowalert/personnel.do',    
					lock : true,
					max : true,
					min : true,
					ok : function() {
						var rows = this.content.getSelected();
						if (rows != null) {
							$(mrows).each(function(i) {
								grid.updateCell('zd007UseCode', rows[0].zd001Code, mrows[i]);
								grid.updateCell('zd008UseName', rows[0].zd002Name, mrows[i]);
							});
						}
						this.content.Close();
						return false;
					},
					cancelVal : '关闭',
					cancel : true
				}).zindex();
}
//删除行
function deleteRow()
{ 
	grid.deleteSelectedRow();
}

function submitForm(param){
	$("#paramflag").val(param);
	var data = grid.getData();
	if (data.length == 0) {
		$.dialog.alert("您没有选择具体生产的产品，无法操作！");
		return false;
	}
	var ba = true;
	if(data !=null){ 
		for (var i = 0;i < data.length;i++){
			var row = data[i]; 
			if(undefined == row.zd013Quantity
					|| isNaN(row.zd013Quantity)
					|| row.zd013Quantity <= 0){
	           	 $.dialog.alert("您第"+(i+1)+"行的“返工数量”不合法");
	           	 ba=false;
	           	 return false;
	        }
			if(row.zd030PlanQuantity<(row.zd013Quantity+row.zd016ProductionQuantity)){
				$.dialog.alert("您第"+(i+1)+"行的“返工数量”大于“订单数量”无法派工");
	           	 ba=false;
	           	 return false;
			}
		}
	}
	jQuery.ajaxSettings.async = false;
	if (ba) {
		$("#itemdata").val(JSON.stringify(data));
		$("#submitFlag").val(param);
		$("#inputForm").submit();
	}
 }
</script>

</head>

<body>

<form id="inputForm" action="" method="post">
<input type="hidden" id="id" name="id" value="${rework.id}"/>
<input type="hidden" id="bizVersion" name="bizVersion" value="${rework.bizVersion}"/>
<input type="hidden" id="itemdata" name="itemdata"/>
<input type="hidden" id="paramflag" name="paramflag"/>
<!-- 用于标识提交按钮 -->
<input type="hidden" id="submitFlag" value="" />
 <div class="pageContent" >
    <div class="panel">
         <table class="TableBlock" align="center">
         			<c:if test="${not empty rework.zd001FormCode}">
         			<tr>
                    <td>生产返工单号:</td>
   		                 <td colspan="3">
   		                <input type="text" id="zd001FormCode" name="zd001FormCode" readonly="readonly" style="width: 40%;"  value="${rework.zd001FormCode}" />
   		                 </td>
   		           </tr>
   		           </c:if>
   		           <tr>
   		                  <td >生产返工单号:</td>
   		                 <td>
   		                <input type="text" id="zd002OriCode" name="zd002OriCode" class="required" readonly="readonly" style="width: 40%;" value="${rework.zd002OriCode}" />
   		                 <input type="button" value="..." onclick="PlanWindow();"/>
   		                 </td>
   		                  <td >PI编号:</td>
   		                 <td>
   		                <input type="text" id="zd003PiCode" name="zd003PiCode" class="required" readonly="readonly" style="width: 40%;" value="${rework.zd003PiCode}" />
   		                </td>
   		           </tr>
                   <tr>
   		             <td >客户编码:</td>
   		                 <td>
   		                 <input type="hidden" id="zd004CustomerId" name="zd004CustomerId" class="required" readonly="readonly" style="width: 40%;" value="${rework.zd004CustomerId}" />
   		                <input type="text" id="zd004CustomerCode" name="zd004CustomerCode" class="required" readonly="readonly" style="width: 40%;" value="${rework.zd004CustomerCode}" />
   		                 </td>  
   		              <td >客户名称:</td>
   		                 <td>
   		                <input type="text" id="zd004CustomerName" name="zd004CustomerName" class="required" readonly="readonly" style="width: 40%;" value="${rework.zd004CustomerName}" />
   		                 </td>     
   		           </tr>
   		           <tr>
   		           	<td >备注:</td>
   		           	<td colspan="3"><input id="zd009Remark" name="zd009Remark" style="width: 40%;" value="${rework.zd009Remark}" /></td>
   		           </tr>
   		           <tr>
						<td colspan="4" style="margin-bottom: 10px;"><div
								id="dataGrid"></div></td>
					</tr>
                </table>               
         </div>
         <div class="formBar">
	        <ul>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="save" onclick="submitForm('PROREWORK_SAVE')">保存</button></div></div></li>
		       <li><div class="buttonActive"><div class="buttonContent"><button type="button" id="tijiao" onclick="submitForm('PROREWORK_END')">提交</button></div></div></li>
		       <li><div class="button"><div class="buttonContent"><button type="button" class="print" onclick="CloseDialog()">关闭</button></div></div></li>
	        </ul>
        </div>    
    </div>
</form>
</body>
</html>
